window.onload = function () {
    findById();
    findAll();
}

function findById() {
    axios.get("/reply/findById").then(resp => {
        let info = resp.data;
        $("channelSpan").innerHTML = info.channel.name;
        $("themeSpan").innerHTML = info.title;
        $("titleSpan").innerHTML = info.title;
        $("landLord").innerHTML = info.user.name;
        $("head").src = "/img/" + info.user.head;
        $("date").innerHTML = info.user.date;
        $("theme").innerHTML = info.title;
        $("time").innerHTML = info.date;
        $("content").innerHTML = info.content;
    })
}

function findAll() {
    axios.get("/reply/findAll").then(resp => {
        let info = resp.data;
        let str = "";
        info.forEach(n => {
            str += `<tr><td>${n.title}</td><td>${n.content}</td><td>${n.user.name}</td></tr>`
        })
        $("data").innerHTML = str;
    })
}

function addReply() {
    axios.get("/reply/add", {
        params: {
            title: $("topic").value,
            content: $("replyContent").value
        }
    }).then(resp => {
        if (resp.data == "ok") {
            location.href = "/forum/reply.html";
        }
    })
}
